#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import logging

from scrapy.crawler import CrawlerRunner
from scrapy.utils.log import configure_logging
from scrapy.utils.project import get_project_settings
from twisted.internet import reactor

# 引入spiders
from caiji.spiders.xiaolai import Xiaolai

logger = logging.getLogger(__name__)
settings = get_project_settings()
configure_logging(settings)
runner = CrawlerRunner(settings)


def start_spider():
    # 装载爬虫
    runner.crawl(Xiaolai)

    # 爬虫结束后停止事件循环
    d = runner.join()
    d.addBoth(lambda _: reactor.stop())
    # 启动事件循环
    reactor.run()
def main():
    start_spider()
if __name__ == '__main__':
    main()